﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
//using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    class TimeSensor : Sensor
    {
        //private string time;
        private Timer myTimer;
        private const int TIMER_INTERVAL = 60000;
        public TimeSensor()
        {
            name = "Time Sensor";
            //data = DateTime.Now.TimeOfDay.ToString() + " " + DateTime.Now.DayOfWeek.ToString();
            data=DateTime.Now.DayOfWeek+", "+DateTime.Now.Hour+":"+DateTime.Now.Minute;
            myTimer = new Timer(); //Initialize Timer
            myTimer.Elapsed += new ElapsedEventHandler(timerEventArrived);
            myTimer.Interval = TIMER_INTERVAL;
            myTimer.Start();
        }
        public string getTime()
        {
            return (string)data;
        }
        public void timerEventArrived(object source, ElapsedEventArgs f)
        {
            //MessageBox.Show("Timer event arrived");
            data = DateTime.Now.TimeOfDay.ToString() + " " + DateTime.Now.DayOfWeek.ToString();
            Notify();
        }
        public void setTime()
        {
            data = DateTime.Now.TimeOfDay.ToString() + " " + DateTime.Now.DayOfWeek.ToString();
            Notify();
        }
    }
}
